import { StatusMonitorConfiguration } from 'nest-status-monitor';

const Transport = {
  REDIS: 6379,
};
const DefaultConfig = {
  HostPort: 3003,
  Socket: {
    prot: 30030,
    namespace: 'events',
  },
  Redis: {
    port: 6379,
    host: '127.0.0.1',
    password: '',
},
};

const WXAPI = {
  accessToken: 'https://api.weixin.qq.com/cgi-bin/token',
  checkNet: 'https://api.weixin.qq.com/cgi-bin/callback/check',
  getWebAuthToken: 'https://api.weixin.qq.com/sns/oauth2/access_token',
  getWxUserInfo: 'https://api.weixin.qq.com/sns/userinfo',
  qrcodeCreate: 'https://api.weixin.qq.com/cgi-bin/qrcode/create',
  showQrcode: 'https://mp.weixin.qq.com/cgi-bin/showqrcode',
  getTicket: 'https://api.weixin.qq.com/cgi-bin/ticket/getticket',
  getUserInfoWithOpenId: 'https://api.weixin.qq.com/cgi-bin/user/info',
};

const AppKey = {
  // WX: {
  //   appID: 'wxd910453889202e59', // 'wx359372afbd951313',
  //   appsecret: '94b5a11a9d39854013f471e3dd718824',
  //   defaultToken: 'o2s1pa1lv32khjkd12h3z2h3um1h23u',
  // },
  WX: {
    appID: 'wx359372afbd951313',
    appsecret: 'f0f75d6bc2f84dbc715a6765c2fbe349',
    defaultToken: 'o2s1pa1lv32khjkd12h3z2h3um1h23u',
  },
};

// tslint:disable-next-line: no-any
const GetSearchParams = (params: any): string => {

  if (!params) {
    return '';
  }
  const paramsArray = [];
  // 拼接参数
  Object.keys(params).forEach((key) => paramsArray.push(key + '=' + params[key]));
  return '?' + paramsArray.join('&');
};

const RedisConfig = {
  transport: Transport.REDIS,
  options: {
    url: 'redis://localhost:6379',
  },
};

const StatusConfig: StatusMonitorConfiguration = {

    pageTitle: 'server-wx monitoring',
    path: '/status',
    port: 3003,
    ignoreStartsWith: '',
    spans: [
      {
        interval: 1, // Every second
        retention: 60, // Keep 60 datapoints in memory
      },
      {
        interval: 5, // Every 5 seconds
        retention: 60,
      },
      {
        interval: 15, // Every 15 seconds
        retention: 60,
      },
    ],
    chartVisibility: {
      cpu: true,
      mem: true,
      load: true,
      responseTime: true,
      rps: true,
      statusCodes: true,
    },
    healthChecks: [],
  };

export default StatusConfig;
export { WXAPI, GetSearchParams, AppKey, DefaultConfig, Transport, RedisConfig };
